from api.base import Base
from loguru import logger


class UserManagerApi(Base):

    def __init__(self):
        self.add_user_url = self.get_url('admin/admin/create')
        self.update_user_url = self.get_url('admin/admin/update')
        self.search_user_url = self.get_url('admin/admin/list?page=1&limit=20&sort=add_time&order=desc')
        self.delete_user_url = self.get_url('admin/admin/delete')
        # self.login()

    def add_user(self,username,password,**kwargs):
        user_data = {'username':username,'password':password}
        if kwargs:
            logger.info('添加管理员的可选参数：{}',kwargs)
            user_data.update(kwargs)
        return self.post(self.add_user_url,user_data)

    def update_user(self,id,username,password,**kwargs):
        user_data = {'id':id,'username':username,'password':password}
        if kwargs:
            user_data.update(**kwargs)
        return self.post(self.update_user_url,user_data)

    def search_user(self):
        return self.get(self.search_user_url)

    def delete_user(self,id,username,**kwargs):
        user_data = {'id': id, 'username': username}
        if kwargs:
            user_data.update(**kwargs)
        return self.post(self.delete_user_url, user_data)

if __name__ == '__main__':
    user = UserManagerApi()
    b = user.add_user('teeee1','teeee1',roleIds=1,avatar='e:/a.jpg')
    print(b)








































